package com.etime.shycourse.controller.wx.courselist;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.etime.shy.common.ListMessage;
import com.etime.shycourse.config.PageMessage;
import com.etime.shycourse.dto.WXCourseTypeListDto;
import com.etime.shycourse.dto.WXOffLineCourseShowDto;
import com.etime.shycourse.pojo.Course;
import com.etime.shycourse.pojo.Organization;
import com.etime.shycourse.services.wxcourselist.WXCourseListService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 小程序课程列表页面相关控制类接口
 */
@RestController
@RequestMapping("/wx/courselist")
@Api(tags = "微信-课程列表页面相关数据接口")
public class WXCourseListController {

    @Autowired
    private WXCourseListService wxCourseListService;

    /**
     * 查询小程序端课程类型列表
     * @return
     */
    @ApiOperation("获取课程分类列表")
    @GetMapping("/typelist")
    public ListMessage<WXCourseTypeListDto> selectCourseTypeList(){
        ListMessage<WXCourseTypeListDto> msg = new ListMessage<>();
        List<WXCourseTypeListDto> list = wxCourseListService.selectCourseTypeList();
        msg.setCode(1);
        msg.setDatalist(list);
        return msg;
    }

    /**
     * 微信小程序中，课程列表页面-查询课程列表数据接口
     * @param param 条件参数
     * @param pagenum 第几页
     * @param pagesize 每页多少行
     * @return
     */
    @ApiOperation("获取课程列表数据接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pagenum",value = "第几页"),
            @ApiImplicitParam(name = "pagesize",value = "每页多少行"),
            @ApiImplicitParam(name="coursetypeid",value = "课程类型id"),
            @ApiImplicitParam(name="courseptypeid",value = "课程父类型id"),
            @ApiImplicitParam(name="keyword",value = "关键字"),
            @ApiImplicitParam(name="orgid",value = "课程所属机构id"),
            @ApiImplicitParam(name="courseaudiences",value = "课程适用人群"),
            @ApiImplicitParam(name="coursetype",value = "课程类型,1-线上课程\n" +
                    "2-线下课程\n" +
                    "3-支招课程"),
            @ApiImplicitParam(name="orderby",value = "排序方式")
    })
    @GetMapping("/coursepage")
    public PageMessage<Course> selectCourseList(CourseSelectParam param,Long pagenum, Long pagesize){
        PageMessage<Course> msg = new PageMessage<>();
        Page<Course> page = wxCourseListService.selectCourseListByPage(param,pagenum,pagesize);
        msg.setCode(1);
        msg.setPagedata(page);
        return msg;
    }
    /**
     * 微信小程序中，课程列表页面-查询课程列表数据接口
     * @param param 条件参数
     * @param pagenum 第几页
     * @param pagesize 每页多少行
     * @return
     */
    @ApiOperation("获取课程列表数据接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pagenum",value = "第几页"),
            @ApiImplicitParam(name = "pagesize",value = "每页多少行"),
            @ApiImplicitParam(name="coursetypeid",value = "课程类型id"),
            @ApiImplicitParam(name="courseptypeid",value = "课程父类型id--不传"),
            @ApiImplicitParam(name="keyword",value = "关键字"),
            @ApiImplicitParam(name="orgid",value = "课程所属机构id"),
            @ApiImplicitParam(name="courseaudiences",value = "课程适用人群"),
            @ApiImplicitParam(name="coursetype",value = "固定值：2,课程类型,1-线上课程\n" +
                    "2-线下课程\n" +
                    "3-支招课程"),
            @ApiImplicitParam(name="orderby",value = "排序方式")
    })
    @GetMapping("/offlinecoursepage")
    public PageMessage<WXOffLineCourseShowDto> selectOffLineCourseList(CourseSelectParam param, Long pagenum, Long pagesize){
        PageMessage<WXOffLineCourseShowDto> msg = new PageMessage<>();
        Page<WXOffLineCourseShowDto> page = wxCourseListService.selectOffLineCourseListByPage(param,pagenum,pagesize);
        msg.setCode(1);
        msg.setPagedata(page);
        return msg;
    }
    /**
     * 查询所有可用的机构列表。用于在课程列表中根据机构进行筛选
     * @return
     */
    @ApiOperation("查询所有可用的机构列表。用于在课程列表中根据机构进行筛选")
    @GetMapping("/orglist")
    public ListMessage<Organization> selectOrgListByUsed(){
        ListMessage<Organization> msg = new ListMessage<>();
        List<Organization> list = wxCourseListService.selectOrgListByUsed();
        msg.setCode(1);
        msg.setDatalist(list);
        return msg;
    }

    /**
     * 查询支招课程列表
     * @return
     */
    @ApiOperation("查询所有支招课程列表（审核通过及已经发布）")
    @GetMapping("/zhizhao")
    public ListMessage<Course> selectZhizhaoList(){
        ListMessage<Course> msg = new ListMessage<>();
        List<Course> list = wxCourseListService.selectZhiZhaoCourseList();
        if(list!=null && list.size()>0) {
            msg.setCode(1);
            msg.setDatalist(list);
        }else{
            msg.setCode(0);
            msg.setMsg("没有支招课程");
        }
        return msg;
    }
}
